<?php

/**
 * Cita filter form base class.
 *
 * @package    toyomotor
 * @subpackage filter
 * @author     Ing. Roberto Hernández De La Luz at Netosfera
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseCitaFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'fecha'               => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'hora'                => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'fecha_entrega'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'hora_entrega'        => new sfWidgetFormFilterInput(),
      'hora_preferida'      => new sfWidgetFormFilterInput(),
      'detalles'            => new sfWidgetFormFilterInput(),
      'observacion'         => new sfWidgetFormFilterInput(),
      'detalles_usuario'    => new sfWidgetFormFilterInput(),
      'kilometraje'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'status'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'is_aceptado'         => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'is_pending'          => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'encuesta'            => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'claveseguridad'      => new sfWidgetFormFilterInput(),
      'created_at'          => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'id_usuario'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Usuario'), 'add_empty' => true)),
      'id_vehiculo_usuario' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('VehiculoUsuario'), 'add_empty' => true)),
      'id_vendedor'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Vendedor'), 'add_empty' => true)),
      'servicios_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Servicio')),
    ));

    $this->setValidators(array(
      'fecha'               => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'hora'                => new sfValidatorPass(array('required' => false)),
      'fecha_entrega'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'hora_entrega'        => new sfValidatorPass(array('required' => false)),
      'hora_preferida'      => new sfValidatorPass(array('required' => false)),
      'detalles'            => new sfValidatorPass(array('required' => false)),
      'observacion'         => new sfValidatorPass(array('required' => false)),
      'detalles_usuario'    => new sfValidatorPass(array('required' => false)),
      'kilometraje'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'status'              => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'is_aceptado'         => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'is_pending'          => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'encuesta'            => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'claveseguridad'      => new sfValidatorPass(array('required' => false)),
      'created_at'          => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'id_usuario'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Usuario'), 'column' => 'id_usuario')),
      'id_vehiculo_usuario' => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('VehiculoUsuario'), 'column' => 'id_vehiculo_usuario')),
      'id_vendedor'         => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Vendedor'), 'column' => 'id_usuario')),
      'servicios_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Servicio', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('cita_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addServiciosListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.ServiciosCita ServiciosCita')
      ->andWhereIn('ServiciosCita.id_servicio', $values)
    ;
  }

  public function getModelName()
  {
    return 'Cita';
  }

  public function getFields()
  {
    return array(
      'id_cita'             => 'Number',
      'fecha'               => 'Date',
      'hora'                => 'Text',
      'fecha_entrega'       => 'Date',
      'hora_entrega'        => 'Text',
      'hora_preferida'      => 'Text',
      'detalles'            => 'Text',
      'observacion'         => 'Text',
      'detalles_usuario'    => 'Text',
      'kilometraje'         => 'Number',
      'status'              => 'Number',
      'is_aceptado'         => 'Boolean',
      'is_pending'          => 'Boolean',
      'encuesta'            => 'Boolean',
      'claveseguridad'      => 'Text',
      'created_at'          => 'Date',
      'id_usuario'          => 'ForeignKey',
      'id_vehiculo_usuario' => 'ForeignKey',
      'id_vendedor'         => 'ForeignKey',
      'servicios_list'      => 'ManyKey',
    );
  }
}
